package com.itheima.mall.service.omsService;

import com.itheima.mall.exception.ConsumerException;

import com.itheima.mall.template.OssTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author yin
 * @date 2022/10/13 14:20
 */
@Service
public class OssService {

    @Autowired
    private OssTemplate ossTemplate;


    /**
     * 图片上传
     * @param photoFile
     * @return
     */
    public String photoUpload(MultipartFile photoFile) {
        String imagePath = null;
        try {
            //调用图片上传功能
            imagePath = ossTemplate.uploadImage(photoFile.getOriginalFilename(), photoFile.getInputStream());
        } catch (IOException e) {
            throw new ConsumerException("图片上传失败");
        }
        return imagePath;
    }
}
